﻿

using HBase;
using HBase.db;
using hCommand;
using Net.http;
using Persistence;
using System.Collections.Generic;

namespace WebApi {
    [FormAuthenticationFilter]

    [RoutePrefix("corewhloc")]
    public class CoreWhLocController : BaseApiController {
        ICoreWhLocServer coreWhLocServer = WMSDalFactray.getDal<ICoreWhLocServer>();

        //库位分页查询
        [HttpPost, Route("FindPage")]
        public BaseResult FindPage([FromBody] CoreWhLocDto dto) {
            Page<CoreWhLoc> info = coreWhLocServer.QueryLocPage(dto);
            return BaseResult.Ok(info);
        }
        //库位保存修改
        [HttpPost, Route("save"), ControlName("库位保存")]
        public BaseResult Save([FromBody] CoreWhLoc coreLoc) {
          
            if (coreLoc.id == 0) {
                coreLoc.id = coreLoc.ShelfId * 100000 + coreLoc.ColNo * 1000 + coreLoc.RowNo * 10 + coreLoc.deepIndex;
                var old = coreWhLocServer.getById<CoreWhLoc>(coreLoc.id);
                if (old != null) {
                    return BaseResult.Error("货位已经存在!");
                } 
                coreWhLocServer.insert(coreLoc);
                return BaseResult.Ok("添加成功!");
            } else {
               var res= WMSTransactionFacade.doLocEngine(coreLoc.id,coreLoc.ActiveStatus,coreLoc.areaId); 
                return BaseResult.Ok(res.msg);
            }
           
        }
        //库位保存修改
        [HttpPost, Route("delete"), ControlName("删除货位")]
        public BaseResult delete([FromBody] CoreWhLoc coreLoc) {
            coreWhLocServer.delete(coreLoc);
            return BaseResult.Ok("添加成功!");
        }
        //库位批量编辑
        [HttpPost, Route("BatchEdit/{areaid}"), ControlName("库位批量编辑")]
        public BaseResult BatchEdit([FromBody] List<long> locList, long areaid) {
            if (locList.Count == 0) {
                return BaseResult.Ok("请选择货位！");
            }
            WMSTransactionFacade.doBatchLocAreaEngine(locList, areaid); 
            return BaseResult.Ok("成功！");
        }
    }
}